<script>
	setInterval(function() {
	window.location.reload();
	}, 500);
</script>

<?php
/**
 * @author Steffen Brem <steffenbrem@gmail.com>
 * 
 * This PHP script will compile the cube core files into the main cube.js file, so that you only need
 * to include the cube.js file in your website.
 */

include 'jsmin.php';

$files = array(
	'core/Cube.js',
	'Logger.js',
	'Array.js',
	'String.js',
	'core/Loader.js',
	'core/Class.js',
	'core/ClassManager.js',
	'core/Base.js',
	'util/Observable.js',
	'data/HttpRequest.js',
	'Ajax.js',
	'Element.js',
	'Component.js'
);

$compiler = new CubeCompiler('cube-dev', 'cube-js/library', $files);
$compiler->compile();
 
 
class CubeCompiler
{
	private $_destination;
	private $_root;
	private $_sourceFiles = array();
	
	public function __construct($destination, $root, $sourceFiles)
	{
		$this->_destination = $destination;
		$this->_root = rtrim($root, '/') . '/';
		$this->_sourceFiles = $sourceFiles;
	}
	
	public function compile()
	{
		$handle = fopen($this->_root . $this->_destination . '.js', 'a+');
		
		ftruncate($handle, 0);
			
		foreach ($this->_sourceFiles as $file)
		{
			$contents = file_get_contents($this->_root . $file);
			$contents .= "\r\n\r\n";
			
			fwrite($handle, $contents);
		}
		
		fclose($handle);
		
		$handle = fopen($this->_root . $this->_destination . '.min.js', 'w+');
		fwrite($handle, JSMin::minify(file_get_contents($this->_root . $this->_destination . '.js')));
		fclose($handle);
	}
}
